package com.project.controller;

import com.project.entity.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class UploadController {
    @PostMapping("upload")
    public Result upload(@RequestParam("file") MultipartFile file) throws IOException {
        Result result = new Result();

        //获取上传的文件的文件名
        String fileName = file.getOriginalFilename();

        //创建上传路径
        File f = new File("D:\\study\\xszx\\vueStudy\\rxt_ui\\src\\assets\\touxiang\\" +fileName);
        System.out.println(fileName);
        f.createNewFile();

        //将流的数据写到文件中
        file.transferTo(f);
        return result.success(fileName);
    }
}
